/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/28
 * Time:16:40
 **/
public class Main1 {
    /**
     * 每日一题-取手套问题
     *
     * @param n
     * @param left
     * @param right
     * @return
     */
    public int findMinimum(int n, int[] left, int[] right) {
        int sum = 0;
        int leftMin = Integer.MAX_VALUE;
        int rightMin = Integer.MAX_VALUE;
        int leftSum = 0;
        int rightSum = 0;
        for (int i = 0; i < n; i++) {
            if (left[i] * right[i] == 0) {//左右手套有0；则最坏的情况要全部拿走
                sum += (left[i] + right[i]);
            } else {
                leftMin = Math.min(leftMin, left[i]);
                rightMin = Math.min(rightMin, right[i]);
                leftSum += left[i];
                rightSum += right[i];
            }
        }
        return sum + Math.min(leftSum - leftMin + 1, rightSum - rightMin + 1) + 1;
    }
}
